package com.dzy.config;

import javax.xml.ws.Endpoint;

import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.dzy.interceptor.AuthInInterceptor;
import com.dzy.service.impl.UnityServiceImpl;

/**
 * @Description
 * cxf webservice配置发布
 * @author Dzy(yndxc@163.com)
 * created by 2016年11月24日下午5:06:39
 */
@Configuration
@EnableConfigurationProperties(IpConf.class)
public class WebServiceConfig {
	@Autowired
    private Bus bus;
	
	@Autowired
	private IpConf ipConf;
	
	@Bean
    public ServletRegistrationBean dispatcherServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/*");
    }
	
    
    @Bean
    public Endpoint unityService() {
        //因为是在这里new出来的，所以在UnityServiceImpl里面是无法使用spring注入功能
    	EndpointImpl endpoint = new EndpointImpl(bus, new UnityServiceImpl());
        endpoint.publish("/UnityService");
        endpoint.getInInterceptors().add(new AuthInInterceptor(ipConf.getIp()));
        return endpoint;
    }
}
